﻿#region Header
/*
 * name：LanguageEntry
 * author：Kain
 * date：12/2/2010 2:50:50 PM
 *********************************************
 * History:
 * $Header$
 * $History$
 */
#endregion

#region imported namespace
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
#endregion

namespace Cherry.Agile.Globalization
{
	class LanguageEntry
	{
        Dictionary<string, string> _dict;

        public string Key { get; private set; }

        internal LanguageEntry( Dictionary<string, string> dict)
        {
            _dict = dict;
            Key = dict["key"];
        }


        public string this[System.Globalization.CultureInfo cultrue]
        {
            get
            {
                string value;
                if (_dict.TryGetValue(cultrue.Name.ToLower(), out value))
                    return value;
                else
                    return string.Empty;
            }
            //set
            //{
            //     
            //}
        }


        internal static LanguageEntry GetEntry(IDataReader reader)
        {
            var length = reader.FieldCount;
            var dict = new Dictionary<string, string>();
            var key = string.Empty;
            for (int i = 0; i < length; i++)
            {
                var name = reader.GetName(i).ToLower();
                dict.Add(name, reader.GetString(i));
            }
            return new LanguageEntry(dict);
        }
	}
}
